package com.xyy.ec.qualification.enums;

import org.springframework.util.StringUtils;

public enum DBTypeEnum {
    SQL_SERVER(1,"SQL Server","SqlServer", "com.microsoft.sqlserver.jdbc.SQLServerDriver"),
    MYSQL(2,"MYSQL","MySQL", "com.mysql.jdbc.Driver"),
    ORACLE(3,"Oracle数据库","Oracle", "oracle.jdbc.driver.OracleDriver"),
    SQL_SERVER_V2000(4,"SQL Server2005","jtds", "net.sourceforge.jtds.jdbc.Driver"), //sqlserver2000
    ORACLE_9I(5,"Oracle9i数据库","Oracle9i", "oracle.jdbc.driver.OracleDriver"),
    ;
    private Integer no;
    private String desc;
    private String dbType;
    private String driver;

    /**
     * 根据dbType获取driver
     * @param dbType
     * @return
     */
    public static String getDriver(String dbType) {
        DBTypeEnum dbTypeEnum = getDBType(dbType);
        return dbTypeEnum == null ? null : dbTypeEnum.getDriver();
    }

    /**
     * 根据dbType获取Enum
     * @param dbType
     * @return
     */
    public static DBTypeEnum getDBType(String dbType) {
        if(StringUtils.isEmpty(dbType)) {
            return null;
        }

        for(DBTypeEnum dbTypeEnum : values()) {
            if(dbTypeEnum.getDbType().toLowerCase().equals(dbType.toLowerCase())) {
                return dbTypeEnum;
            }
        }

        return null;
    }


    DBTypeEnum(Integer no, String desc, String dbType, String driver) {
        this.no = no;
        this.desc = desc;
        this.dbType = dbType;
        this.driver = driver;
    }

    public String getDbType() {
        return dbType;
    }


    public String getDriver() {
        return driver;
    }

    public Integer getNo() {
        return no;
    }

    public String getDesc() {
        return desc;
    }
}
